/**
 * @author dnk2
 */

var xmlHttp ;
 
function requestTasks() {
	var player = readCookie("koru_user") ;
		
	var parPlayer = newElementAtt('param', '', new Array('name', 'value'), new Array('player', player) ) ;
		
	var paramList = newElement('paramList', parPlayer);
  		 
  	var request = newElementAtt('request', paramList, new Array('lang', 'to', 'type', 'uid'), new Array('en',collection + '/GetTaskList', 'process', '1'  ) );
  	var message = newElement('message', request );
  	var soapMessage = messageToSOAP(message);
   
  	xmlHttp = XmlHttp.create();
  	xmlHttp.open("POST", "http://" + serverPath + "/services/localsite", true);
  	xmlHttp.onreadystatechange = new Function("processTasksResponse() ; ") ;
   
	xmlHttp.setRequestHeader("SOAPAction", "\"\"");
  	xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
   
   	//logDebug("Request: " + message) ;
   
  	xmlHttp.send(soapMessage);
}



function processTasksResponse() {
	if (xmlHttp.readyState == 4) {
		logDebug("Task Response: " + xmlHttp.responseXML.xml) ;
		
		var tasks = xmlHttp.responseXML.getElementsByTagName('task') ;
		
		
		var taskList = document.getElementById("taskList") ;
		
		for(var i=0 ; i<tasks.length ; i++) {
			var task = tasks[i] ;			
			
			var li = document.createElement("li") ;
			
			var rank = document.createElement("div") ;
			rank.className = "ranking" ;
			rank.innerHTML = task.getAttribute("ranking") ;
			li.appendChild(rank) ;
			
			var name = document.createElement("div") ;
			name.className = "name" ;
			name.innerHTML = "<a href='game.htm?task=" + task.getAttribute("id") + "'>" + task.getAttribute("title") + "</a>" ;
			li.appendChild(name) ;
			
			var description = document.createElement("div") ;
			description.className = "description" ;
			description.innerHTML = task.getAttribute("description") ;
			li.appendChild(description) ;
			
			taskList.appendChild(li) ;
			
			if (i%2 == 0) {
				li.style.backgroundColor = "#def392" ;
			}
			
		}
	}	
}